<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>将一个一维数组的值转化为字符串</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.implode" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">implode</h1>
  <p class="verinfo">(PHP 4, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">implode</span> &mdash; <span class="dc-title">将一个一维数组的值转化为字符串</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.implode-description">
  <h3 class="title">说明</h3>
   <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>implode</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$glue</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter">$pieces</code></span>
   ) : <span class="type">string</span></div>

  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>implode</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter">$pieces</code></span>
   ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   用 <code class="parameter">glue</code> 将一维数组的值连接为一个字符串。
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    因为历史原因，<span class="function"><strong>implode()</strong></span> 可以接收两种参数顺序，但是 <span class="function"><a href="explode.html" class="function">explode()</a></span> 不行。不过按文档中的顺序可以避免混淆。
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.implode-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">glue</code></dt>

     <dd>

      <p class="para">
       默认为空的字符串。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">pieces</code></dt>

     <dd>

      <p class="para">
       你想要转换的数组。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.implode-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回一个字符串，其内容为由 glue 分割开的数组的值。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.implode-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5915">
    <p><strong>Example #1 <span class="function"><strong>implode()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /><br />$array&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">'lastname'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'email'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'phone'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$comma_separated&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">","</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$array</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">$comma_separated</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;lastname,email,phone<br /><br />//&nbsp;Empty&nbsp;string&nbsp;when&nbsp;using&nbsp;an&nbsp;empty&nbsp;array:<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">implode</span><span style="color: #007700">(</span><span style="color: #DD0000">'hello'</span><span style="color: #007700">,&nbsp;array()));&nbsp;</span><span style="color: #FF8000">//&nbsp;string(0)&nbsp;""<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>   
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.implode-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">此函数可安全用于二进制对象。</span></p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.implode-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="explode.html" class="function" rel="rdfs-seeAlso">explode()</a> - 使用一个字符串分割另一个字符串</span></li>
    <li class="member"><span class="function"><a href="preg_split.html" class="function" rel="rdfs-seeAlso">preg_split()</a> - 通过一个正则表达式分隔字符串</span></li>
    <li class="member"><span class="function"><a href="http_build_query.html" class="function" rel="rdfs-seeAlso">http_build_query()</a> - 生成 URL-encode 之后的请求字符串</span></li>
   </ul>
  </p>
 </div>


</div></div></div></body></html>